#ifndef calendarpanel_h
#define calendarpanel_h

#include "juce_amalgamated.h"
#include "ListPanel.h"
#include "CalendarView.h"

class GroceryListView;

class CalendarPanel: public ListPanel {
private:
	int currentItem;
	CalendarView* clView;
public:
	CalendarPanel(MasterComponent* master, int w, int h) :
		ListPanel(master, w, h), currentItem(0) {

		deque<Eatable>& meals = getEatableList();
		copy(meals.begin(), meals.end(), inserter(filteredItems, filteredItems.begin()));

		addAndMakeVisible(clView = new CalendarView(this));
		clView->setBounds(35, 94,  5 * width / 7 - 70, h - 123);
		backButton->setFromTo(MasterComponent::CALENDAR, MasterComponent::MAIN);

		listBox->updateContent();

		showItemView(0);
		setWantsKeyboardFocus(true);
	}

	~CalendarPanel() {
		delete clView;
	}

	void setGroceryListView(GroceryListView* glView) {
		clView->setGroceryListView(glView);
	}

	void paint(Graphics& g) {
		Rectangle r(0, 0, width, height);
		g.setColour(Colours::palegoldenrod);
		g.fillRoundedRectangle(r, 50);
		g.setColour(Colours::grey);
		MiscGraphics::drawRoundedRect(g, r, 50, 1);

		g.setColour(Colours::black);
		g.setFont(Font(Font::getDefaultSansSerifFontName(), 36, Font::plain));
		g.drawFittedText(T("Meal Scheduler"), 0, 0, width, 100, Justification::centred, 1);

//		cout << "painting" << getWidth() << " " << getHeight() << endl;
		paintListBox(g);
	}

	void switchPanels(int from, int to) {
		master->switchPanels(from, to);
	}

	deque<Eatable>& getEatableList() {
		return PersistentFoodList::instance().getMeals();
	}

	void showItemView(int row) {
		currentItem = row;
	}

	void doubleClicked(const MouseEvent& e) {

	}

	void addToDay(int id) {
		clView->addToDay(id, filteredItems[currentItem]);
	}

	void subtractFromDay(int id) {
		clView->subtractFromDay(id);
	}

	void switchToGroceryList() {
		master->switchPanels(MasterComponent::CALENDAR, MasterComponent::GROCERY_LIST);
	}
};

#endif
